Skip to content

Algorithms

Alt text

Writing algorithms

  • Structured English is a method of showing the logical steps in an algorithm, using an agreed subset of straightforward English words for commands and mathematical operations to represent the solution. These steps can be numbered.
  • Flowchart shows diagrammatically, using a set of symbols linked together with flow lines, the steps required for a task and the order in which they are to be performed. These steps, together with the order, are called an algorithm. Flowcharts are an effective way to show the structure of an algorithm.
  • Pseudocode is a method of showing the detailed logical steps in an algorithm, using keywords, identifiers with meaningful names and mathematical operators to represent a solution. Pseudocode does not need to follow the syntax of a specific programming language, but it should provide sufficient detail to allow a program to be written in a high-level language.

Structured English

1 Ask for the number of values
Loop that number of times
2 Enter a value in loop
Add the value to the Total in loop
Calculate and output average

Flowchart

Alt text

Pseudocode

ALevel Pseudocode

Total <- 0
PRINT "Enter the number of values to average"
INPUT Number
FOR Counter  1 TO Number
    PRINT "Enter value"
    INPUT Value
    Total <- Total + Value
NEXT Counter
Average <- Total / Number
PRINT "The average of ",Number,m values is ",Average

Writing pseudocode from a structured English description

  • From a structured English description, the following things need to be possible:
    • Any variables that need to be used can be identified and put in an identifier table – these can be items input or output as the results of calculations.
    • Input and output can be identified from the wording used, for example, Enter, Read, Print, Write.
    • Selection can be identified from the wording used, for example, If, Then, Choose.
    • Any iteration required can be identified from the wording used, for example, Loop, Repeat.
    • Any processes needed can be identified from the wording used, for example, Set, Calculate.

Writing pseudocode from a flowchart

  • Flowcharts can be used to identify any variables required and you can then complete an identifier table.
  • Each flowchart symbol can be used to identify and write one or more pseudocode statements.

Alt text

Stepwise refinement

  • When an algorithm is written to solve a more complex problem, decomposition is used to break the problem down into smaller and more manageable parts.
  • These parts then need to be written as a series of steps where each step can be written as a statement in a high-level programming language, this process is called stepwise refinement.

stepwise refinement

1  Enter time taken to run marathon in hours, minutes and seconds

2  Calculate and store marathon time in seconds

3  Output marathon time in seconds

  • 1  Enter time taken to run marathon in hours, minutes and seconds

    • 1.1  Enter the hours

    • 1.2  Enter the minutes

    • 1.3  Enter the seconds

Structured English

is a method of showing the logical steps in an algorithm, using an agreed subset of straightforward English words for commands and mathematical operations to represent the solution

[0/1]

Flowchart

shows diagrammatically, using a set of symbols linked together with flow lines, the steps required for a task and the order in which they are to be performed.

[0/1]

Pseudocode

is a method of showing the detailed logical steps in an algorithm, using keywords, identifiers with meaningful names and mathematical operators to represent a solution.

[0/1]

Stepwise refinement

When an algorithm is written to solve a more complex problem, decomposition is used to break the problem down into smaller and more manageable parts. These parts then need to be written as a series of steps where each step can be written as a statement in a high-level programming language, this process is called

[0/1]